<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <title>DawnSql编辑器</title>
    <link href="/static/js/resources/ext-theme-neptune/ext-theme-neptune-all.css" rel="stylesheet"/>
    <script src="/static/js/ext-all.js" type="text/javascript"></script>
    <script src="/static/js/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
    <script src="/static/js/jquery-3.4.0.min.js" type="text/javascript"></script>
    <script src="/static/js/MyUtils.js" type="text/javascript"></script>
    <script type="text/javascript">
        function my_get_items(lst, my_stack, big_small, my_stack_lst, rs)
        {
            var f = first(lst);
            if (f != null)
            {
                var r = rest(lst);
                if (f == '"' && big_small == null)
                {
                    my_stack.push(f);
                    my_stack_lst.push(f);
                    return my_get_items(r, my_stack, '大', my_stack_lst, rs);
                }
                else if (f == '"' && big_small != null)
                {
                    if (my_stack_lst.length == 1)
                    {
                        my_stack.push(f);
                        return my_get_items(r, my_stack, null, [], rs);
                    }
                    else if (my_stack_lst.length > 1)
                    {
                        my_stack.push(f);
                        my_stack_lst.pop();
                        return my_get_items(r, my_stack, '大', my_stack_lst, rs);
                    }
                    else
                    {
                        alert('字符串错误！');
                    }
                }
                else if (f == '\'' && big_small == null)
                {
                    my_stack.push(f);
                    my_stack_lst.push(f);
                    return my_get_items(r, my_stack, '小', my_stack_lst, rs);
                }
                else if (f == '\'' && big_small != null)
                {
                    if (my_stack_lst.length == 1)
                    {
                        my_stack.push(f);
                        return my_get_items(r, my_stack, null, [], rs);
                    }
                    else if (my_stack_lst.length > 1)
                    {
                        my_stack.push(f);
                        my_stack_lst.pop();
                        return my_get_items(r, my_stack, '小', my_stack_lst, rs);
                    }
                    else
                    {
                        alert('字符串错误！');
                    }
                }
                else if (f == ';' && big_small == null)
                {
                    if (my_stack.length > 0)
                    {
                         my_stack.push(f);
                         rs.push(my_stack);
                        return my_get_items(r, [], null, [], rs);
                    }
                    else
                    {
                        my_stack.push(f);
                        rs.push(my_stack);
                        return my_get_items(r, [], null, [], rs);
                    }
                }
                else
                {
                    my_stack.push(f);
                    return my_get_items(r, my_stack, big_small, my_stack_lst, rs);
                }
            }
            return rs;
        }

        /*
        function my_get_items_1(lst)
        {
            return my_get_items(lst, [], null, [], []);
        }
         */

        function get_lst_sql(line)
        {
            var rs = my_get_items(my_comment(Array.from(line)), [], null, [], []);
            var lst = [];
            for (var i in rs)
            {
                lst.push(Ext.String.trim(rs[i].join('')));
            }
            return lst;
        }

        $(function () {
            $('#btn').click(function () {
                var line = Ext.String.trim($('#txt').val());
                var vs = line.match(/^create\s+table\s+IF\s+NOT\s+EXISTS\s+\w+\s+\(/i);
                if (vs != null)
                {
                    //var mline = vs[0].replace(new RegExp(/^create\s+table\s+IF\s+NOT\s+EXISTS\s+/i,"g"), "");
                    var mline_1 = vs[0].replace(new RegExp(/\s+\($/i,"g"), "");
                    console.log(mline_1);
                }
                //var lst = get_lst_sql(line);
                console.log(vs);
                //$('#p').html(lst.join('  '));
            });
        });
    </script>
</head>
<body>
   <textarea id="txt" style="height: 226px; width: 684px;">

   </textarea>
   <input type="button" value="添加表定义" id="btn" />
   <p id="p"></p>
</body>
</html>